<extend name="./Application/Admin/View/Layout/application.html"/>
<block name="css">
    <link rel="stylesheet" href="__PUBLIC__/assets/admin/css/common.css">
</block>

<block name="content">
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">广告列表</strong> /
                    <small>Ad List</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a class="am-btn am-btn-default" href="{{:U('add')}}"><span
                                    class="am-icon-plus">新增</span> </a>


                            <a class="am-btn am-btn-default" href=""><span class="am-icon-plus "
                                                                           id="delete_all">删除</span> </a>

                        </div>
                    </div>
                </div>

                <form action="">
                    <div class="am-u-sm-12 am-u-md-3">

                    </div>

                    <div class="am-u-sm-12 am-u-md-4">
                        <div class="am-input-group am-input-group-sm">
                            <input type="text" name="title" placeholder="按标题" class="am-form-field">
                            <span class="am-input-group-btn">
                                <button class="am-btn am-btn-default" type="submit">搜索</button>
                                 <a href="{{:U('Advert/index')}}" class="am-btn am-btn-default">重置</a>
                            </span>
                        </div>
                    </div>
                </form>

            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form" action="" id="form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check"><input type="checkbox" class="check_all"></th>
                                <th class="table-id">编号</th>
                                <th class="table-date am-hide-sm-only">缩略图</th>
                                <th class="table-date am-hide-sm-only">标题</th>
                                <th class="table-date am-hide-sm-only">广告地址</th>
                                <th class="table-date am-hide-sm-only">描述信息</th>
                                <th class="table-date am-hide-sm-only">排序</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="adverts" id="advert">
                                <tr data-id="{{$advert.id}}">
                                    <td><input type="checkbox" class="checked_id" name="ids[]" value="{{$advert.id}}"/>
                                    </td>
                                    <td>{{$advert.id}}</td>
                                    <td>
                                        <img src="{{$advert.thumb}}" alt=""
                                             style="width: 80px;height: 60px;">
                                    </td>
                                    <td><a href="#">{{$advert.title}}</a></td>
                                    <td><a href="{{$advert.url}}" target="_blank">{{$advert.url}}</a></td>
                                    <td>{{$advert.description}}</td>


                                    <td>
                                        <input type="text" class="sort_order" value="{{$advert.sort_order}}"
                                               style="width: 40px">
                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="{{:U('edit',['id'=>$advert[id]])}}"
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                        class="am-icon-pencil-square-o"></span> 编辑
                                                </a>
                                                <a class="delete_advert am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </volist>

                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {{$count}} 条记录
                            <div class="am-fr">
                                <ul class="am-pagination">
                                    {{$page}}
                                </ul>
                            </div>
                        </div>
                        <hr/>
                        <p>注：.....</p>
                    </form>
                </div>

            </div>
        </div>
        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>
    </div>
    <!-- content end -->




</block>
</block>

<block name="js">
    <script>
        $(function () {
            //全选，反选
            $('.check_all').click(function () {
                var checked = $(this).prop('checked');
                $('.checked_id').prop('checked', checked);
            })
            //ajax多条删除
            $('#delete_all').click(function () {
                var length = $('.checked_id:checked').length;
                if (length == 0) {
                    alert('请至少选中一条');
                    return false;
                }
                $.post("{{:U('delete_all')}}", $('.checked_id:checked').serialize(), function () {
                    $('.checked_id:checked').each(function () {
                        $(this).parents('tr').fadeOut(400);

                    })
                })
                return false;
            })
            //单条删除
            $('.delete_advert').click(function () {
                if (confirm('确认删除此广告吗？')) {
                    var id = $(this).parents('tr').data('id');
                    $.post("{{:U('delete_one')}}", {id: id}, function () {
                        $("tr[data-id = '" + id + "' ]").fadeOut(400);
                    })
                }
                return false;
            })

            //排序
            $('.sort_order').change(function () {
                var info = {
                    id: $(this).parents('tr').data('id'),
                    sort_order: $(this).val()
                }
                $.post("{{:U('sort_order')}}", info, function () {
                    location.href = "{{:U('Advert/index')}}"
                })
                return false;
            })


        })
    </script>
</block>

